import re

from django.db.models.fields import json
from django.shortcuts import render

# Create your views here.
from django.views import View
from application.user.models import User
from django.http import JsonResponse


class GetUser(View):

    # 获取数据 查询数据是否存在
    def get(self, request, username):
        # if not re.match('^[a-zA-Z]+[a-zA-Z0-9]{5}', username):
        #     return JsonResponse({"code": 200, "errmsg": '用户名称不符合规则'})
        count = User.objects.filter(name=username).count()
        return JsonResponse({"code": 200, "count": count, "errmsg": 'ok'})


# 注册
class Register(View):

    # 新增数据
    def post(self, request):
        data = request.body
        print(data)
        return JsonResponse({"code": 200, "errmsg": 'ok'})